package com.smt.common.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Enumeration;

/**
 * 判断session中是否存在该值
 *
 * @author zhangyi
 * @date 2018/10/23 10:15
 */
public class ExistSessionKeyUtil {

    public static String get(HttpServletRequest request,String key){
        String value = null;
        HttpSession session = request.getSession();
        Enumeration<String> attributeNames = session.getAttributeNames();
        while(attributeNames.hasMoreElements()){
            String s = attributeNames.nextElement();
            Object attribute = session.getAttribute(s);
            if(s.equals(key)){
                value = (String) attribute;
            }
        }
        return value;
    }
}
